package com.neuedu.ssm.controller;

import com.neuedu.ssm.po.Dept;
import com.neuedu.ssm.service.IDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 金山
 * 项目：springmvc-learn
 * site: https://blog.fulfill.com.cn
 * 描述
 * @data 2025/3/1814:33
 */
@RestController
@RequestMapping("/dept")
public class DeptController {

    @Autowired
    private IDeptService deptService;


    @GetMapping("/{id}")
    public Dept getByid(@PathVariable long id){

        return deptService.getById(id);
    }

    @GetMapping("/list")
    public List<Dept> list(){

        return deptService.list();
    }


    /**
     * 更新
     * @param dept
     * @return
     */
    @PostMapping()
    public boolean update(@RequestBody Dept dept    ){

        if(dept.getDeptId() != null ){
            return deptService.update(dept);
        }else{
            return deptService.save(dept);
        }
    }

    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable long id){

       return  deptService.delete(id);
    }



}
